import {
  BoxGeometry,
  MeshBasicMaterial,
  Mesh,
  MeshLambertMaterial,
  Color,
} from "three";
import Base from "../Base";

export default class Box {
  private cube: Mesh;
  private cubeMaterial: MeshBasicMaterial;

  constructor() {
    const base = Base.getInstance();
    this.cubeMaterial = new MeshBasicMaterial({ color: 0x00ff00 });
    const cube = this.createCube();
    this.cube = cube;
    base.scene.add(cube);
    const cube2 = new Mesh(
      new BoxGeometry(1, 1, 1),
      new MeshBasicMaterial({ color: 0x00ff00 })
    );
    cube2.position.setX(3);
    base.scene.add(cube2);

    this.initCubeEvent();
  }
  private createCube() {
    const cube = new Mesh(new BoxGeometry(1, 1, 1), this.cubeMaterial);
    cube.position.y = 0.5;
    return cube;
  }
  private initCubeEvent() {
    this.cube.addEventListener("mouseenter", (e) => {
      console.log("鼠标进入");
      this.cubeMaterial.color = new Color(0xff0000);
    });
    this.cube.addEventListener("mousemove", (e) => {
      console.log("鼠标正在移动");
    });

    this.cube.addEventListener("mouseleave", (e) => {
      console.log("鼠标离开");
      this.cubeMaterial.color = new Color(0x00ff00);
    });
    this.cube.addEventListener("click", (e) => {
      console.log("鼠标点击");
      this.cubeMaterial.color = new Color(0x0000ff);
    });
  }
}
